<template>
  <KiFormDialog
    :show.sync="showDiaLog"
    title="引入方设置"
    v-model="loginForm"
    :retrieve="() => {}"
    :submit="setting"
  >
    <template #el-form>
      <el-form-item
        label="选择引入方"
        prop="agent"
        :rules="{ required: true, message: '请选择引入方', trigger: 'change' }"
      >
        <el-select
          v-model="loginForm.agent"
          style="width: 100%"
          filterable
          clearable
        >
          <el-option
            v-for="item in agents"
            :key="item.companyId"
            :label="item.companyName"
            :value="item.companyId"
          ></el-option>
        </el-select>
        <!-- <form-item-tips value="修改新的引入方后，新的引入方获得该企业的引入方权。清空下拉框后，取消当前引入方的引入方权。" /> -->
      </el-form-item>
    </template>
  </KiFormDialog>
</template>
<script>
// 引入方审核
export default {
  name: 'agent-setting',
  data () {
    return {
      showDiaLog: false,
      loginForm: {
        agent: ''
      },
      row: null,
      loading: false,
      agents: []
    }
  },
  methods: {
    show (row) {
      this.row = row
      this.loading = false
      this.showDiaLog = true
      this.loginForm.agent = row.belongAgencyId || ''
      this.getAgents()
    },
    // 获取引入方列表
    getAgents () {
      this.$POST('sot-admin-api/sys/agency/listForSelect', {
        status: '1'
      }).then(res => {
        if (res.errorCode == '00000') {
          this.agents = res.data
        } else {
          this.$swal.success(res.message)
        }
      })
    },
    setting () {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$POST('sot-admin-api/company/setAgency', {
            id: this.row.companyId,
            belongAgencyId: this.loginForm.agent || ''
          })
            .then(res => {
              if (res.errorCode == '00000') {
                this.$swal.success('设置成功')
                this.showDiaLog = false
                this.$emit('serttingSuccess')
              } else {
                this.$swal.success(res.message)
              }
            })
            .finally(() => {
              this.loading = false
            })
        }
      })
    }
  }
}
</script>
